<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<title><?= $sf_response->getTitle() ?></title>
<?php use_stylesheet('approve') ?>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">

<h1>View <?php echo $bom->getWono() ?></h1>

<div id="sf_admin_content">

<fieldset id="sf_fieldset_none" class="">
<?php 
    if ($bom->getReviseId()) { ?>
        <input type="hidden" name="bom[revise_id]" id="bom_revise_id" value="<?php echo $bom->getReviseId() ?>" >
<?}        
?>
<div class="form-row">
  <?php echo label_for('bom[wono]', __($labels['bom{wono}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('bom{wono}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('bom{wono}')): ?>
    <?php echo form_error('bom{wono}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

<!--Tien-->
  <?php $default = CommonValues::GenerateAutoNumber('BOM', $bom->getWono(), 'BOM')   ?>
   <input name="bom[wono]" id="bom_wono" value="<?php echo $default ?>"  type="hidden">
   <input name="bom_wono_show" id="bom_wono_show" value="<?php echo $default ?>" size="15" disabled="disabled" type="text">
   </div>
</div>

<div class="form-row">
  <?php echo label_for('bom[project_id]', __($labels['bom{project_id}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('bom{project_id}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('bom{project_id}')): ?>
    <?php echo form_error('bom{project_id}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_select_tag($bom, 'getProjectId', array (
  'related_class' => 'Project',
  'control_name' => 'bom[project_id]',
  'disabled'=>1,
)); 
    if ($bom->getReviseId())  {?>     
   <input name="bom[project_id]" id="bom_project_id" value="<?php echo$bom->getProjectId() ?>"  type="hidden">
   <input name="bom_wono_show" id="bom_wono_show" value="<?php echo $bom->getProject() ?>" size="30" disabled="disabled" type="text">
    <?}
    else 
        echo $value ? $value : '&nbsp;' ?>
    </div>
    <!--Hai nut Approve Hay Reject -->
   
</div>
</div>




<div class="form-row">
  <?php echo label_for('bom[status]', __($labels['bom{status}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('bom{status}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('bom{status}')): ?>
    <?php echo form_error('bom{status}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php 
        $status = $bom->getStatus()? $bom->getStatus(): CommonValues::$gBomStatus['key']['Initial'];
        $gStatus = CommonValues::$gBomStatus['value']; 
   ?>
    <input name="bom[status]" id="bom_status" value="<?php echo $status ?>"  type="hidden">
    <input name="bom_status_show" id="bom_status_show" value="<?php echo $gStatus[$status] ?>" size="10" disabled="disabled" type="text">
    </div>
    <div>
    
     </div>
</div>
</fieldset>

<!--Tien code here
get information for MR-->
<?php
    if ($bom->getComponentgroupId()){
        $componentGroupId = $bom->getComponentgroupId();
        
        $c = new Criteria();
        $c->add(ComponentsPeer::COMPONENTGROUP_ID , $componentGroupId);
        $c->addAscendingOrderByColumn(ComponentsPeer::ID);
        
        $componentList = ComponentsPeer::doSelect($c);
    }
?>


<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" width="25%">Product Code
              </th>
      <th id="sf_admin_list_th_description" width="35%">Description
              </th>
      <th id="sf_admin_list_th_description" width="10%">Brand
              </th>       
      <th id="sf_admin_list_th_description" width="10%">Unit
              </th>
      
      <th id="sf_admin_list_th_description">Qty need</th>
      <th id="sf_admin_list_th_description">Supplied by Client</th>
</tr>
</thead>
<!--show component here-->
 <?php if (isset($bom->rowIds) && count($bom->rowIds)) {
    foreach ($bom->rowIds as $key=>$id) { 
        $component1= ComponentPeer::retrieveByPK($id);?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $component1->getId()?>"/>
            <td><?echo $component1->getProductcode()?></td>
            <td><?echo $component1->getDescription()?></td>
            <td><?echo $component1->getBrand()?></td>
            <td><?echo $component1->getComponentunit()?></td>
            <td><input type="text" name="qtys[]" id ="qtys" size="5" value ="<?echo $bom->qtys[$key]?>"></td>
            <td><input type="checkbox" name="suppliedByClients[]" id ="suppliedByClients"  value="<?php echo $component1->getId();?>"        
        <?php 
            $bSupplied = false;
            for ($j = 0; isset($bom->suppliedByClients) && $j < count($bom->suppliedByClients) ; $j++) {
                if ($bom->suppliedByClients[$j] == $id) {
                    $bSupplied = true;
                    break;
                }
            }
            if ($bSupplied) echo "checked";
        ?>></td>
            <td><ul class="sf_admin_td_actions"><li><?php echo  image_tag(sfConfig::get('sf_admin_web_dir').'/images/delete_icon.png', array('align' => 'absmiddle', 'alt' => 'delete', 'title' =>'delete', 'onclick' => 'removeComponent('.$component1->getId().',"added_components", ".ExistComponents")', 'onmouseover'=>'this.style.cursor="pointer"'))?></li></ul></td>
        </tr>
<?} } elseif (isset($componentList) && $componentList) {
    foreach ($componentList as $key=>$components) { 
        $component1= ComponentPeer::retrieveByPK($components->getComponentId());?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $component1->getId()?>"/>
            <td><?echo $component1->getProductcode()?></td>
            <td><?echo $component1->getDescription()?></td>
            <td><?echo $component1->getBrand()?></td>
            <td><?echo $component1->getComponentunit()?></td>
            <td><input type="text" name="qtys[]" id ="qtys" size="5" disabled value ="<?echo $components->getQty1()?>"></td>
            <td><input type="checkbox" name="suppliedByClients[]" id ="suppliedByClients" disabled value="<?php echo $components->getComponentId();?>"  <?php if (1 ==$components->getQty2()) echo "checked"?>></td>
        </tr>
<?php } }?>
</table>
<ul class="sf_admin_actions">
  <li><?php echo button_to(__('Approve'), 'approval/ApproveObject?authenticationMain=APPROVE_BOM&authenticationSub=PR_APPROVE_MR&mod=BOM&id='.$bom->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_BOM~3authenticationSub~4PR_APPROVE_MR~3mod~4BOM~3backURL~4', array (
  'class' => 'sf_admin_action_approve',
  'confirm' => __('Are you sure you want to approve this BOM?'),
)) ?></li>
  <li><?php echo button_to(__('Reject'), 'approval/RejectObject?authenticationMain=APPROVE_BOM&authenticationSub=PR_APPROVE_MR&mod=BOM&id='.$bom->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_BOM~3authenticationSub~4PR_APPROVE_MR~3mod~4BOM~3backURL~4', array (
  'class' => 'sf_admin_action_reject',
)) ?></li>
    </ul>
</div>

</div>

